package c.e.b.m.l;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import org.json.JSONException;
import org.json.JSONObject;

/* compiled from: PersistedInstallation */
public class c {
    public final File a;
    public final c.e.b.c b;

    /* compiled from: PersistedInstallation */
    public enum a {
        ATTEMPT_MIGRATION,
        NOT_GENERATED,
        UNREGISTERED,
        REGISTERED,
        REGISTER_ERROR
    }

    public c(c.e.b.c cVar) {
        cVar.a();
        File filesDir = cVar.a.getFilesDir();
        StringBuilder g = c.b.a.a.a.g("PersistedInstallation.");
        g.append(cVar.c());
        g.append(".json");
        this.a = new File(filesDir, g.toString());
        this.b = cVar;
    }

    public d a(d dVar) {
        try {
            JSONObject jSONObject = new JSONObject();
            jSONObject.put("Fid", dVar.c());
            jSONObject.put("Status", dVar.f().ordinal());
            jSONObject.put("AuthToken", dVar.a());
            jSONObject.put("RefreshToken", dVar.e());
            jSONObject.put("TokenCreationEpochInSecs", dVar.g());
            jSONObject.put("ExpiresInSecs", dVar.b());
            jSONObject.put("FisError", dVar.d());
            c.e.b.c cVar = this.b;
            cVar.a();
            File createTempFile = File.createTempFile("PersistedInstallation", "tmp", cVar.a.getFilesDir());
            FileOutputStream fileOutputStream = new FileOutputStream(createTempFile);
            fileOutputStream.write(jSONObject.toString().getBytes("UTF-8"));
            fileOutputStream.close();
            if (createTempFile.renameTo(this.a)) {
                return dVar;
            }
            throw new IOException("unable to rename the tmpfile to PersistedInstallation");
        } catch (IOException | JSONException unused) {
        }
    }

    /* JADX WARNING: Missing exception handler attribute for start block: B:15:0x002c */
    public c.e.b.m.l.d b() {
        /*
        r14 = this;
        r0 = new java.io.ByteArrayOutputStream;
        r0.<init>();
        r1 = 16384; // 0x4000 float:2.2959E-41 double:8.0948E-320;
        r2 = new byte[r1];
        r3 = 0;
        r4 = new java.io.FileInputStream;	 Catch:{ IOException | JSONException -> 0x002d, IOException | JSONException -> 0x002d }
        r5 = r14.a;	 Catch:{ IOException | JSONException -> 0x002d, IOException | JSONException -> 0x002d }
        r4.<init>(r5);	 Catch:{ IOException | JSONException -> 0x002d, IOException | JSONException -> 0x002d }
    L_0x0011:
        r5 = r4.read(r2, r3, r1);	 Catch:{ all -> 0x0028 }
        if (r5 >= 0) goto L_0x0024;
    L_0x0017:
        r1 = new org.json.JSONObject;	 Catch:{ all -> 0x0028 }
        r0 = r0.toString();	 Catch:{ all -> 0x0028 }
        r1.<init>(r0);	 Catch:{ all -> 0x0028 }
        r4.close();	 Catch:{ IOException | JSONException -> 0x002d, IOException | JSONException -> 0x002d }
        goto L_0x0032;
    L_0x0024:
        r0.write(r2, r3, r5);	 Catch:{ all -> 0x0028 }
        goto L_0x0011;
    L_0x0028:
        r0 = move-exception;
        r4.close();	 Catch:{ all -> 0x002c }
    L_0x002c:
        throw r0;	 Catch:{ IOException | JSONException -> 0x002d, IOException | JSONException -> 0x002d }
    L_0x002d:
        r1 = new org.json.JSONObject;
        r1.<init>();
    L_0x0032:
        r0 = 0;
        r2 = "Fid";
        r2 = r1.optString(r2, r0);
        r4 = c.e.b.m.l.c.a.ATTEMPT_MIGRATION;
        r5 = "Status";
        r3 = r1.optInt(r5, r3);
        r5 = "AuthToken";
        r5 = r1.optString(r5, r0);
        r6 = "RefreshToken";
        r6 = r1.optString(r6, r0);
        r7 = 0;
        r9 = "TokenCreationEpochInSecs";
        r9 = r1.optLong(r9, r7);
        r11 = "ExpiresInSecs";
        r11 = r1.optLong(r11, r7);
        r13 = "FisError";
        r0 = r1.optString(r13, r0);
        r1 = c.e.b.m.l.d.a;
        r1 = new c.e.b.m.l.a$b;
        r1.m6181init();
        r1.d(r7);
        r1.b(r4);
        r1.c(r7);
        r1.a = r2;
        r2 = c.e.b.m.l.c.a.values();
        r2 = r2[r3];
        r1.b(r2);
        r1.c = r5;
        r1.d = r6;
        r1.d(r9);
        r1.c(r11);
        r1.g = r0;
        r0 = r1.a();
        return r0;
        */
        throw new UnsupportedOperationException("Method not decompiled: c.e.b.m.l.c.b():c.e.b.m.l.d");
    }
}
